package com.lxk.service.impl;

import com.lxk.dao.AsMyMapper;
import com.lxk.dao.WxUserMapper;
import com.lxk.pojo.WxUser;
import com.lxk.pojo.WxUserExample;
import com.lxk.service.UserService;
import com.lxk.vo.PageModel;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

/**
 * @author JohnSoybean
 * @create 2020/3/30 12:08
 * @description
 */
@Service
@Transactional
public class UserServiceImpl implements UserService {

    @Autowired
    private WxUserMapper wum;
    @Autowired
    private AsMyMapper mm;

    public Integer getTotalPages(Integer num) {
        WxUserExample example = new WxUserExample();
        Integer count = (int)wum.countByExample(example);
        Integer totalPages = count%num==0 ? count/num : count/num+1;
        return totalPages;
    }

    public PageModel<WxUser> selUserPage(Integer pageIndex, Integer num, Integer totalPages, Integer sort, Integer order) {
        int start = (pageIndex-1)*num;
        List<WxUser> list = mm.selUserPage(start, num, sort, order);
        PageModel<WxUser> model = new PageModel<WxUser>();
        model.setList(list);
        model.setNum(num);
        model.setPageIndex(pageIndex);
        model.setTotalPages(totalPages);
        return model;
    }

    public WxUser selUserById(Integer wxUserId) {
        WxUser wxUser = wum.selectByPrimaryKey(wxUserId);
        return wxUser;
    }

    public Integer updUser(WxUser wxUser) {
        int upd = wum.updateByPrimaryKeySelective(wxUser);
        return upd;
    }

    public Integer delUser(Integer wxUserId) {
        int del = wum.deleteByPrimaryKey(wxUserId);
        return del;
    }


}
